﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Xml;

    [ScriptType("SP.ListDataValidationExceptionValue", ValueObject=true, ServerTypeId="{356fe248-721a-4adf-af96-20822bc5476e}")]
    public sealed class ListDataValidationExceptionValue : ClientValueObject
    {
        private IList<ListDataValidationFailure> m_fieldFailures;
        private ListDataValidationFailure m_itemFailure;

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = false;
            string str = peekedName;
            if (str != null)
            {
                if (!(str == "FieldFailures"))
                {
                    if (str == "ItemFailure")
                    {
                        flag = true;
                        reader.ReadName();
                        this.m_itemFailure = reader.Read<ListDataValidationFailure>();
                    }
                    return flag;
                }
                flag = true;
                reader.ReadName();
                this.m_fieldFailures = reader.ReadList<ListDataValidationFailure>();
            }
            return flag;
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public override void WriteToXml(XmlWriter writer, SerializationContext serializationContext)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (serializationContext == null)
            {
                throw new ArgumentNullException("serializationContext");
            }
            writer.WriteStartElement("Property");
            writer.WriteAttributeString("Name", "FieldFailures");
            DataConvert.WriteValueToXmlElement(writer, this.FieldFailures, serializationContext);
            writer.WriteEndElement();
            writer.WriteStartElement("Property");
            writer.WriteAttributeString("Name", "ItemFailure");
            DataConvert.WriteValueToXmlElement(writer, this.ItemFailure, serializationContext);
            writer.WriteEndElement();
        }

        [Remote]
        public IList<ListDataValidationFailure> FieldFailures
        {
            get
            {
                return this.m_fieldFailures;
            }
        }

        [Remote]
        public ListDataValidationFailure ItemFailure
        {
            get
            {
                return this.m_itemFailure;
            }
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public override string TypeId
        {
            get
            {
                return "{356fe248-721a-4adf-af96-20822bc5476e}";
            }
        }
    }
}

